//
//  MainTableViewController.m
//  HappyBug
//
//  Created by liulei on 2018/12/20.
//  Copyright © 2018年 www.hc.com.cn. All rights reserved.
//

#import "MainTableViewController.h"
//cell被点击的条目
#import "FMDBViewController.h"
#import "IOSLocalNotificationViewController.h"
#import "PlistRWViewController.h"
#import "UITableViewDelegateStudy.h"
#import "JMUpdataImage.h"
#import "AlertView.h"
#import "GWCarViewController.h"
#import "BaseClassTestViewController.h"
#import "DESViewController.h"
@interface MainTableViewController ()

@end

@implementation MainTableViewController{
    
    UITableView *mainTable;
    NSArray *mainTableArray;
    
    FMDBViewController *fmDB;
    IOSLocalNotificationViewController *localNotication;
    PlistRWViewController *plistRW;
    UITableViewDelegateStudy *tabledelage;
    JMUpdataImage *uploadImg;
    AlertView *alert;
    GWCarViewController *gwcViewController;
    BaseClassTestViewController *baseControler;
    DESViewController *descontroller;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    [self initData];
    
}

-(void)initData{
    
    mainTableArray=@[@"数据库操作",@"iOS本地通知",@"Plist文件读取",@"TableView的代理方法操作",@"选择上相册图片上传",@"自定义UIAlertView",@"购物车页面",@"DES加解密",@"9"];
    
}
-(void)initView{
    UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(40, 20, Width-40*2, 30)];
    label.text=@"Test列表";
    label.textAlignment=NSTextAlignmentCenter;
    [self.view addSubview:label];
    
    mainTable =[[UITableView alloc]initWithFrame:CGRectMake(0,label.frame.size.height+label.frame.origin.y+5,Width,Height) style:UITableViewStylePlain];
    mainTable.delegate=self;
    mainTable.dataSource=self;
    [self.view addSubview:mainTable];
    
    //数据库页面
    fmDB=[[FMDBViewController alloc]init];
    localNotication=[[IOSLocalNotificationViewController alloc]init];
    plistRW=[[PlistRWViewController alloc]init];
    tabledelage=[[UITableViewDelegateStudy alloc]init];
    uploadImg=[[JMUpdataImage alloc]init];
    alert =[[AlertView alloc]init];
    gwcViewController=[[GWCarViewController alloc]init];
    baseControler=[[BaseClassTestViewController alloc]init];
    descontroller =[[DESViewController alloc]init];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ID=@"mainCell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
    if(!cell){
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    cell.textLabel.text=mainTableArray[indexPath.row];
    return cell;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return  [mainTableArray count];
}

//cell 被点击
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    switch (indexPath.row) {
        case 0:
            [self presentViewController:fmDB animated:YES completion:nil];
            break;
        case 1:
            [self presentViewController:localNotication animated:YES completion:nil];
            break;
        case 2:
            [self presentViewController:plistRW animated:YES completion:nil];
            break;
        case 3:
            [self presentViewController:tabledelage animated:YES completion:nil];
            break;
        case 4:
            [self showSheetView];
            break;
        case 5:
            [alert showAlert];
            break;
        case 6:
            [self.navigationController pushViewController:baseControler animated:YES];
            break;
        case 7:
            [self presentViewController:descontroller animated:YES completion:nil];
            break;
            
        default:
            break;
    }
}

-(void)showSheetView{
    
    UIAlertController *alertController =[UIAlertController alertControllerWithTitle:@"提示" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self->uploadImg updateLogo:self];
    }];
    UIAlertAction *takeAction = [UIAlertAction actionWithTitle:@"照相" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self->uploadImg camera:self];
    }];
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    
    [alertController addAction:takeAction];
    [alertController addAction:okAction];
    [alertController addAction:cancelAction];
    [self presentViewController:alertController animated:YES completion:nil];

}
@end
